package cn.jingyuan.swan.cloud.oauth2.exceptions;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import cn.jingyuan.swan.cloud.core.Result;
import cn.jingyuan.swan.cloud.oauth2.error.DefaultOAuth2ExceptionSupport;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class DefaultOAuth2ExceptionSerializer extends StdSerializer<DefaultOAuth2Exception> {

    public DefaultOAuth2ExceptionSerializer() {
        super(DefaultOAuth2Exception.class);
    }

    @Override
    public void serialize(DefaultOAuth2Exception ex, JsonGenerator gen, SerializerProvider provider) throws IOException {
        Result rs = DefaultOAuth2ExceptionSupport.resolve(ex);
        gen.writeObject(rs);
    }

}
